package wojtek.gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import javax.swing.JButton;

public class Rama extends JFrame {

	private JPanel contentPane;

private JTextField txtMarka;
private JTextField txtModel;

Ramka ramka;
Ramka danaRamka;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Ramka rama1 = new Ramka();

					Rama frame = new Rama(rama1);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Rama(Ramka ramka) {
		this.danaRamka = ramka;
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
		
		txtMarka = new JTextField();
		txtMarka.setText(danaRamka.getMarka());
		txtMarka.getDocument().addDocumentListener(new DocumentListener(){
			public void changedUpdate(DocumentEvent e)
			{
			danaRamka.setMarka(txtMarka.getText());
		}

			@Override
			public void insertUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void removeUpdate(DocumentEvent e) {
				// TODO Auto-generated method stub
				
			}
	
		});
		
		
		contentPane.add(txtMarka, "10, 4, fill, default");
		txtMarka.setColumns(10);
		
		JLabel lblMarka = new JLabel("Marka");
		contentPane.add(lblMarka, "14, 4");
		
		txtModel = new JTextField();
		txtModel.setText(danaRamka.getModel());
		contentPane.add(txtModel, "10, 6, fill, default");
		txtModel.setColumns(10);
		
		JLabel lblModel = new JLabel("Model");
		contentPane.add(lblModel, "14, 6");
		
		JCheckBox chckbxSprawne = new JCheckBox("Sprawne");
		contentPane.add(chckbxSprawne, "10, 8");
		
		JButton btnZapisz = new JButton("Zapisz");
		contentPane.add(btnZapisz, "10, 10");
	}

}
